import http from "@/api";
import { ReqPage, ResPage } from "@/api/interface";

const baseUrl: string = "/queue/delay_queue_message";

export interface DelayQueueMessagePageParam extends ReqPage {
  // 延迟队列id
  queueId?: string;
  // 消息状态 参考字典: DelayQueueMessageStatus
  status?: number;
  // 预计时间
  expectTime?: string | string[];
}

export interface DelayQueueMessagePageResult {
  // 主键id
  id: string;
  // 延迟队列id
  queueId: string;
  // 消息内容
  message: string;
  // 消息状态 参考字典: DelayQueueMessageStatus
  status: number;
  // 预计时间
  expectTime: string;
}

export const getDelayQueueMessagePage = (param: DelayQueueMessagePageParam) => {
  return http.get<ResPage<DelayQueueMessagePageResult>>(baseUrl + `/page`, param);
};

export interface DelayQueueMessageInfoResult {
  // 主键id
  id: string;
  // 延迟队列id
  queueId: string;
  // 消息内容
  message: string;
  // 消息状态 参考字典: DelayQueueMessageStatus
  status: number;
  // 预计时间
  expectTime: string;
}

export const getDelayQueueMessageInfo = (id: string) => {
  return http.get<DelayQueueMessageInfoResult>(baseUrl + `/info/` + id);
};

export interface DelayQueueMessageSaveParam {
  // 延迟队列id
  queueId?: string;
  // 消息内容
  message?: string;
  // 预计时间
  expectTime?: string;
}

export const saveDelayQueueMessage = (param: DelayQueueMessageSaveParam) => {
  return http.post(baseUrl + `/save`, param);
};

export interface DelayQueueMessageUpdateParam {
  // 主键id
  id?: string;
  // 消息内容
  message?: string;
  // 预计时间
  expectTime?: string;
}

export const updateDelayQueueMessage = (param: DelayQueueMessageUpdateParam) => {
  return http.post(baseUrl + `/update`, param);
};

export const deleteDelayQueueMessage = (ids: string[]) => {
  return http.post(baseUrl + `/delete`, ids);
};

export const getDelayQueueMessageImportTemplate = () => {
  return http.get<any>(baseUrl + `/import/template`, {}, { loading: true, responseType: "blob" });
};

export const importDelayQueueMessageExcel = (params: FormData) => {
  return http.post(baseUrl + `/import/excel`, params, { cancel: false });
};

export const exportDelayQueueMessageExcel = (param: DelayQueueMessagePageParam) => {
  return http.get<any>(baseUrl + `/export/excel`, param, { loading: true, responseType: "blob" });
};
